<template>
<!--  //步进器设置默认值-->
<!--  <van-stepper v-model="value" />-->
<!--  //-->
    <div class="order">
      <van-empty description="没有商品" v-if="!orderList.length"/>

      <van-card
          :price="order.price"
          :desc="order.description"
          :title="order.name"
          :thumb="order.mainImage"
          v-for="order of orderList"
      >
        <template #footer>
<!--          //步进器组件-->
<!--          <van-stepper v-model="value" theme="round" button-size="22" disable-input />-->
<!--          //单独写（需要写样式同步teacher）-->
         <van-button size="mini" @click="handleAddCart(order.id)">
           <van-icon name="plus" />
              </van-button>
        </template>
      </van-card>
    </div>
</template>

<script>
import {showConfirmDialog} from 'vant';
// import axios from "axios";

export default {
  name: "order",
  props:['business'],
  data(){
    return{
      id: '',
      orderList:[]
    }
  },
  methods:{
    _initOrderList(){
      this.$axios.get(`/ele_server/business/order?businessId=${this.id}`
      ).then(({data: res}) =>{
        // console.log(res)
        if (res.status == 0){
          this.orderList = res.data;
        }else {
          alert(res.message)
        }
      })
    },
    handleAddCart(id){
      console.log(id)
      // const param = {
      //   foodId: id,
      //   quantity:1
      // }
      this.$axios.get(`/ele_server/cart/add?foodId=${id}&quantity=1`).then(({data: res}) =>{
        console.log(res)
        if (res.status == 0) {
          showConfirmDialog({
            title: '提示',
            message: '添加购物车成功',
            confirmButtonText: '去购物车结算',
            cancelButtonText: '继续浏览'
          }).then(() => {
            console.log('点击成功')
            this.$router.push('/cart/list');
          }).catch(() => {})
        } else if (res.status == 3003) {
          showConfirmDialog({
            title: '提示',
            message: '未登录不能添加购物车',
            confirmButtonText: '去登录',
            cancelButtonText: '继续浏览'
          }).then(() => {
            console.log('点击成功')
            this.$router.push(`/user/login?redirect=${this.$route.fullPath}`);
          }).catch(() => {})
        } else {

        }
      })
    }
  },
  created(){
    this.id = this.$route.query.id
    this._initOrderList()

  }
}
</script>


<style scoped lang="stylus">
//- 2 + 的样式
//.order
//  >>>.van-card
//    .van-card__footer
//      display flex
//      justify-content flex-end
//      align-items center
//      .food-count
//        margin-left 5px

</style>